// components/checklist/index.js
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		list: {
			type: Array,
			value: []
		},
		editable: {
			type: Boolean,
			value: true
		},
		selected: {
			type: Array,
			value: []
		}
	},

	/**
	 * 组件的初始数据
	 */
	data: {

	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		clearSelectItem: function(){
			this.setData({
				selected:[],
			})
		},
		selectItem: function(ev) {
			//debugger
			const {
				editable,
				selected
			} = this.data
			if (!editable) return
			const {
				item
			} = ev.currentTarget.dataset
			const currentIdx = selected.indexOf(item)
			if (currentIdx === -1) {
				selected.push(item)
			} else {
				selected.splice(currentIdx, 1)
			}
			this.setData({
				selected
			})
			this.triggerEvent('myEvent', selected, ev, {})
		}
	}
})
